package quick.portal.fragment.email;

import java.util.List;

import com.alibaba.fastjson.JSONArray;

import quick.common.AppContext;
import quick.portal.R;
import quick.portal.activity.WebviewActivity;
import quick.portal.data.EmailInfo;
import quick.portal.fragment.DataListFragment;
import quick.portal.service.BaseService;
import quick.view.quickadapter.BaseAdapterHelper;
import android.content.Intent;
import android.view.View;
import android.widget.PopupMenu;
import android.widget.TextView;


public class EmailUnreadFragment extends DataListFragment<EmailInfo> {
	
	public EmailUnreadFragment()
	{
		this.queryAction = "NoReadEmailList";
    	this.itemViewLayoutId = R.layout.data_list_item_email_unread;
	}
	
	@Override
	protected void adapterConvert(BaseAdapterHelper helper, EmailInfo mail) {
		helper.setText(R.id.title, mail.getTitle())
        .setTag(R.id.title, mail)
        .setText(R.id.fromUserName, mail.getFromUserName())
        .setText(R.id.receiveTime, mail.getReceiveTime());
	}
	
	@Override
	protected void showDetail(View view) {
		TextView tvTitle = (TextView)view.findViewById(R.id.title);
		EmailInfo mail = (EmailInfo)tvTitle.getTag();
    	
		String url = BaseService.getPortalUrl();
		url = url + "/Systems/MyReceiveEmail/Read/" + mail.getId() + "/";
		
		String token = AppContext.getInstance().getToken();
    	url = url + "?" + AppContext.Login_Token_Key + "=" + token;

        Intent intent = new Intent(context,WebviewActivity.class);
        intent.putExtra("Url", url);
        startActivity(intent);
        
	}
	
	@Override
	protected List<EmailInfo> parseArray(String body) {
		List<EmailInfo> list = JSONArray.parseArray(body, EmailInfo.class);
		
		return list;
	}
	
	@Override
	public void setUserVisibleHint(boolean isVisibleToUser) {
		super.setUserVisibleHint(isVisibleToUser);
		
		if(isVisibleToUser)
		{
			PopupMenu menu = this.GetOriginalPopupMenu();
			//menu.getMenu().add(0,WorkOrderFragment.menu_addworkorder,1,"新建工单");
			menu.setOnMenuItemClickListener(this);
		}
	}
	
}
